import requests
import time

API_URL = "http://172.25.6.53:5000/api/error"

def fetch_api_data():
    print("正在调用API...")
    try:
        response = requests.get(API_URL, timeout=5)
        if response.status_code == 200:
            data = response.json()
            print("成功获取数据：", data)
        else:
            print("请求失败，状态码：", response.status_code)
    except requests.ConnectionError:
        print("无法连接到API服务器，请检查网络或服务器地址。")
    except requests.Timeout:
        print("请求超时，请检查服务器是否正常运行。")
    except Exception as e:
        print(f"发生错误：{e}")

if __name__ == "__main__":
    while True:
        fetch_api_data()
        time.sleep(2)
